/**
 * 将数组扁平化
 * @param arr
 */
export function flatArray<T>(
    arr: Array<{ [key: string]: any } & T>,
    childField: string
): T[] {
    if (!arr) return []
    return arr.reduce((acc, val) => {
        acc.push(
            val,
            ...flatArray(val[childField] as Array<{ [key: string]: any } & T>, childField)
        )
        return acc
    }, [] as T[])
}
